package com.dchh.android.suverynew.views;

import android.app.Activity;
import android.graphics.Bitmap;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;

import com.dchh.android.suverynew.R;
import com.dhcc.android.base.common.view.MyPopupWindow;

/**
 * 地图窗口
 *
 * @author zhoudan
 * @date 2016年4月28日
 */
public class MapPopupWindow {

    private MyPopupWindow window;
    private Activity activity;

    public MapPopupWindow(Activity activity) {
        this.activity = activity;
    }

    /**
     * 显示地图
     *
     * @param parent 弹窗载体
     * @param map    地图对应的图片
     */
    public void show(View parent, Bitmap map) {
        if (window == null) {
            View v = LayoutInflater.from(activity).inflate(R.layout.yield_map_window, null);
            ImageView mapview = (ImageView) v.findViewById(R.id.map);
            if (map != null) {
                mapview.setImageBitmap(map);
            }
            ImageView close = (ImageView) v.findViewById(R.id.close);
            close.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (window != null) {
                        window.dismiss();
                    }
                }
            });

            window = new MyPopupWindow(v, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, true);
        }

        window.showAtLocation(parent, Gravity.CENTER, 0, 0);
    }
}
